﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Com.Web.coffinegurunaru.AppLogic.Page;

namespace Com.Web.coffinegurunaru.aboutus.usercontrol
{
	public partial class paging : WebUserControl
	{
		public string PageName { get; set; }
		public string Query { get; set; }

		public int PageNo { get; set; }
		public byte PageSize { get; set; }
		public int TotalCount { get; set; }

		protected int StartPageNo { get; set; }
		protected int EndPageNo { get; set; }
		protected int TotalPageNo { get; set; }

		protected void Page_Load(object sender, EventArgs e)
		{
			if (TotalCount == 0)
			{
				TotalPageNo = 1;
				StartPageNo = 1;
				EndPageNo = 1;
				EndPageNo = 1;
			}
			else
			{
				TotalPageNo = ((TotalCount - 1) / PageSize) + 1;
				StartPageNo = (((PageNo - 1) / 10) * 10) + 1;
				EndPageNo = StartPageNo + 9;
				EndPageNo = TotalPageNo < EndPageNo ? TotalPageNo : EndPageNo;
			}
		}

		public string GetURL(int PageNo)
		{
			this.Query = this.Query == null ? string.Empty : this.Query;
			string Query = this.Query != string.Empty ? (this.Query[0] != '&' ? "&" + this.Query : this.Query) : string.Empty;
			string retValue = this.Request.Url.AbsolutePath + "?" + PageName + "=" + PageNo + Query;
			return retValue;
		}
	}
}